<%--
  Created by IntelliJ IDEA.
  User: K
  Date: 2021/2/11
  Time: 11:35
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<div id="page_nav">
    <%--        ${requestScope.pageBean.url}--%>
    <c:if test="${requestScope.pageBean.currentPage>1}">
        <a href="${pageContext.request.contextPath}${requestScope.pageBean.url}&currentPage=1">首页</a>
        <a href="${pageContext.request.contextPath}${requestScope.pageBean.url}&currentPage=${requestScope.pageBean.currentPage-1}">上一页</a>
    </c:if>


    <c:choose>
        <%--情况一：总页码小于或等于五页--%>
        <c:when test="${requestScope.pageBean.totalPage<=5}">
            <c:forEach begin="1" end="${requestScope.pageBean.totalPage}" var="i">
                <c:if test="${requestScope.pageBean.currentPage==i}">
                    <a href="${pageContext.request.contextPath}${requestScope.pageBean.url}&currentPage=${i}">[${i}]</a>
                </c:if>

                <c:if test="${requestScope.pageBean.currentPage!=i}">
                    <a href="${pageContext.request.contextPath}${requestScope.pageBean.url}&currentPage=${i}">${i}</a>
                </c:if>

            </c:forEach>
        </c:when>


        <%--情况二：总页码大于五页--%>
        <c:when test="${requestScope.pageBean.totalPage>5}">
            <c:choose>
                <%--小情况1：当前页为前三页  遍历前五页--%>
                <c:when test="${requestScope.pageBean.currentPage<=3}">
                    <c:forEach begin="1" end="5" var="i">
                        <c:if test="${requestScope.pageBean.currentPage==i}">
                            <a href="${pageContext.request.contextPath}${requestScope.pageBean.url}&currentPage=${i}">[${i}]</a>
                        </c:if>

                        <c:if test="${requestScope.pageBean.currentPage!=i}">
                            <a href="${pageContext.request.contextPath}${requestScope.pageBean.url}&currentPage=${i}">${i}</a>
                        </c:if>

                    </c:forEach>
                </c:when>

                <%--小情况2： 当前页为后三页  遍历后五页--%>
                <c:when test="${requestScope.pageBean.currentPage>requestScope.pageBean.totalPage-3}">
                    <c:forEach begin="${requestScope.pageBean.totalPage-4}" end="${requestScope.pageBean.totalPage}" var="i">
                        <c:if test="${requestScope.pageBean.currentPage==i}">
                            <a href="${pageContext.request.contextPath}${requestScope.pageBean.url}&currentPage=${i}">[${i}]</a>
                        </c:if>

                        <c:if test="${requestScope.pageBean.currentPage!=i}">
                            <a href="${pageContext.request.contextPath}${requestScope.pageBean.url}&currentPage=${i}">${i}</a>
                        </c:if>

                    </c:forEach>
                </c:when>

                <%--小情况3： 当前页为其它页--%>
                <c:otherwise>
                    <c:forEach begin="${requestScope.pageBean.currentPage-2}" end="${requestScope.pageBean.currentPage+2}" var="i">
                        <c:if test="${requestScope.pageBean.currentPage==i}">
                            <a href="${pageContext.request.contextPath}${requestScope.pageBean.url}&currentPage=${i}">[${i}]</a>
                        </c:if>

                        <c:if test="${requestScope.pageBean.currentPage!=i}">
                            <a href="${pageContext.request.contextPath}${requestScope.pageBean.url}&currentPage=${i}">${i}</a>
                        </c:if>

                    </c:forEach>
                </c:otherwise>

            </c:choose>
        </c:when>

    </c:choose>


    <c:if test="${requestScope.pageBean.currentPage<requestScope.pageBean.totalPage}">
        <a href="${pageContext.request.contextPath}${requestScope.pageBean.url}&currentPage=${requestScope.pageBean.currentPage+1}">下一页</a>
        <a href="${pageContext.request.contextPath}${requestScope.pageBean.url}&currentPage=${requestScope.pageBean.totalPage}">末页</a>
    </c:if>

    共${requestScope.pageBean.totalPage}页，${requestScope.pageBean.totalCount}条记录 到第<input value="4" name="pn" id="pn_input"/>页
    <input  id="jupBtn" type="button" value="确定">
</div>